package com.liu.repository;

import com.liu.domain.health;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.util.Date;
import java.util.List;

/**
 * Created by liu on 17-9-22.
 */
public interface HealthRepository extends JpaRepository<health,Integer>{

    @Query("select s from health s  where rank = '优' and date = (select max(date) from s)" )
    public List<health> findbygood();                 //查询日期最新一天的 得优 寝室

    @Query("select s from health s  where rank = '差' and date = (select max(date) from s)" )
    public List<health> findbybad();


    @Query("select s from health s  where TO_DAYS(s.date) = TO_DAYS(?1)" )
    public List<health> findbytime(Date sj);                            //按日期搜索

    @Query("select s from health s  where r_id = ?1 ")
    public List<health> findbyroom(int r_id);                       //根据学生session room-id查询 卫生


    @Query(value = "select * from health where r_id=?1 and date=?2 ", nativeQuery = true)
    public List<health> findAllByR_idAndDate(int roomId, String date);


    //根据等级查
    @Query(value = "select * from health where rank=?1 ", nativeQuery = true)
    public List<health> findAllByRank(String rank);

}
